package org.gfix.binding;

import java.io.StringReader;
import java.io.StringWriter;

import org.gfix.parser.FixParseFault;
import org.gfix.parser.FixParser;
import org.gfix.parser.MessageSource;
import org.gfix.types.FixVersion;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(JMock.class)
public class ClassToFIXBindingTest {
	protected Mockery context = new JUnit4Mockery();
	
	@Test(expected=FixBindingException.class)
	public void testNoPublicGetterFailsClasses() throws Exception
	{
		FixParser fp = new FixParser();
		FixBinder fb = new FixBinder(fp);
		fb.register(FixMessage1.class);
		
		FixMessage1 output = new FixMessage1();
		output.setBooleanType(Boolean.TRUE);
		final MessageSink sink = new MessageSink() {
			
			@Override
			public void writeTag(int tag, String contents) {	
			}
		};
		
		fb.write(sink, output, FixVersion.FIX_41);
	}
	
	@Test
	public void testClassWrites() throws Exception
	{
		FixParser fp = new FixParser();
		FixBinder fb = new FixBinder(fp);
		fb.register(FullMessage.class);
		
		FullMessage output = new FullMessage();
		output.setBooleanType(Boolean.TRUE);
		final MessageSink sink = context.mock(MessageSink.class);
		
		context.checking(new Expectations()
		{{
		    oneOf(sink).writeTag(8, "FIX.4.1");
		    oneOf(sink).writeTag(35, "D");
		    oneOf(sink).writeTag(71, "true");
		}});
		
		fb.write(sink, output, FixVersion.FIX_41);
	}
}
